package com.teach.flavour.enums;

import com.common.utils.IBaseEnum;
import io.swagger.models.auth.In;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author hzz
 */

public enum MealType implements IBaseEnum {
    RICE(1, "米饭"),
    NOODLE(2, "面条"),
    WHEATEN (3, "面食"),
    OTHER(4, "杂粮");

    private Integer value;
    private String text;

    MealType(int value, String text) {
        this.value = value;
        this.text = text;
    }
    public synchronized static MealType fromCode(Integer code) {
        if (null != code) {
            Optional<MealType> optional = Arrays.asList(MealType.values()).stream().filter(x -> x.getValue() - code==0 ).findAny();
            return optional.isPresent() ? optional.get() : null;
        }

        return null;
    }
    public synchronized static MealType textOf(Integer text) {
        if (null != text) {
            Optional<MealType> optional = Arrays.asList(MealType.values()).stream().filter(x -> x.getText().equals(text) ).findAny();
            return optional.isPresent() ? optional.get() : null;
        }

        return null;
    }
    @Override
    public int getValue() {
        return this.value;
    }

    @Override
    public String getText() {
        return this.text;
    }

    @Override
    public String paraString() {
        return this.paraString();
    }
}
